package com.taoyun.mapper;

import com.taoyun.pojo.entity.Group;
import com.taoyun.pojo.vo.GroupVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lkxicy
 * @since 2020-09-23
 * extends BaseMapper<Group>
 */
@Repository
public interface GroupMapper{

    /**
     * 查询由该管理员（User_Id为Id）创建的所有群组
     * @param Id
     * @return
     */
    @Select("select * from yunpan.group where U_Id=#{Id}")
    @ResultType(Group.class)
    List<Group> ShowGroup(@Param("Id")Integer Id);

    /**
     * 查询群组Id为GroupId的信息
     * @param GroupId
     * @return
     */
    @Select("select * from yunpan.group where GroupId = #{GroupId}")
    @ResultType(Group.class)
    List<Group> ShowInformationOfGroup(@Param("GroupId") Integer GroupId);

    /**
     * 删除群组Id为GroupId的成员（Ids包含的）
     * @param GroupId
     * @param Ids
     * @return
     */
    Integer DeleteUserOfGroup(@Param("GroupId")Integer GroupId,@Param("Ids") List<Integer> Ids);

    @Insert("insert into yunpan.group(GroupId,U_Id,GroupName,Up_Permission,Dl_Permission,L_Permission,Re_Permission,D_Permission," +
            "M_Permission,U_Permission) value(#{group.GroupId},#{group.uId},#{group.GroupName},#{group.upPermission},#{group.dlPermission}," +
            "#{group.lPermission},#{group.rePermission},#{group.dPermission},#{group.mPermission},#{group.uPermission})")
    Integer CreateGroup(@Param("group")Group group);

    //查找group
    @Select("select * from yunpan.group where GroupId = #{GroupId} and U_Id = #{uId}")
    @ResultType(Group.class)
    Group SelectGroupByIdAndUId(@Param("GroupId")Integer GroupId, @Param("uId")Integer uId);

    //根据G_Id查询群组
    @Select("select * from yunpan.group where G_Id = #{G_Id}")
    @ResultType(Group.class)
    Group SelectGroupByGId(@Param("G_Id")Integer G_Id);

    //根据GroupId查询群组
    @Select("select * from yunpan.group where GroupId = #{GroupId} and U_Id=#{U_Id}")
    @ResultType(Group.class)
    Group SelectGroupByGroupId(@Param("GroupId")Integer GroupId,@Param("U_Id")Integer U_Id);

    //拉人进群
    Integer AddUserIntoGroup(@Param("GroupList") List<Group> GroupList);

    //修改群成员上传权限
    Integer ModifyUpPermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("UpPermission")String UpPermission);

    //修改群成员下载权限
    Integer ModifyDlPermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("DlPermission")String UpPermission);
    //修改群成员查看浏览权限
    Integer ModifyLPermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("LPermission")String UpPermission);
    //修改群成员删除权限
    Integer ModifyDPermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("DPermission")String UpPermission);
    //修改群成员重命名权限
    Integer ModifyRePermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("RePermission")String UpPermission);
    //修改群成员移动权限
    Integer ModifyMPermission(@Param("GroupId") Integer GroupId,@Param("Ids")List<Integer> Ids,@Param("MPermission")String UpPermission);

    //根据群组groupId删除群组
    @Delete("delete from yunpan.group where groupId = #{GroupId}")
    Integer DeleteGByGroupId(@Param("GroupId")Integer GroupId);

    //根据U_Id删除群组信息
    @Delete("delete from yunpan.group where U_Id = #{U_Id}")
    Integer DeleteGByUId(@Param("U_Id")Integer U_Id);

    //根据U_Id返回用户所加入群组的群编号GroupId
    @Select("select GroupId from yunpan.group where U_Id = #{U_Id}")
    List<Integer> ShowUserBelongGroup(@Param("U_Id") Integer U_Id);

    //根据U_Id返回用户所加入群组的群编号GroupId
    @Select("select G_Id from yunpan.group where U_Id = #{U_Id}")
    List<Integer> SelectGIdsByUId(@Param("U_Id") Integer U_Id);


}
